﻿using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Xml;
using Common.Logging;
using In.Api.Helpers;
using Newtonsoft.Json;
using In.Api.Dto.HisWs;

namespace In.Api.Controllers
{
    public class HisNewWsController : ApiController
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(HisNewWsController));

        /// <summary>
        /// 获取科室信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetDeptInfo")]
        public Response4GetDeptInfo GetDeptInfo(Request4GetDeptInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();
            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            hospitalIdNode.InnerText = request.HospitalId;
            root.AppendChild(hospitalIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getdeptinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetDeptInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetDeptInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetDeptInfo();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.DeptList = new List<Response4GetDeptInfoSubDeptInfo>();

                var nodes = xmlDoc.SelectNodes("/res/DeptList/deptInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var deptObj = new Response4GetDeptInfoSubDeptInfo();

                    var deptName = xNode.SelectSingleNode("deptName").InnerText;
                    //if (deptName.Contains("护理门诊") || deptName.Contains("超声诊断科") || deptName.Contains("放射科") || deptName.Contains("胎儿医学科门诊"))
                    //{
                    //    continue;
                    //}
                    var deptId = xNode.SelectSingleNode("deptId").InnerText;
                    var loc = xNode.SelectSingleNode("loc").InnerText;
                    var parentId = xNode.SelectSingleNode("parentId").InnerText;
                    var desc = xNode.SelectSingleNode("desc").InnerText;

                    deptObj.DeptId = deptId;
                    deptObj.DeptName = deptName;
                    deptObj.Loc = loc;
                    deptObj.ParentId = parentId;
                    deptObj.Desc = desc;

                    responseObj.DeptList.Add(deptObj);
                }
            }

            return responseObj;

        }

        /// <summary>
        /// 获取医生排班信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetScheduleInfo")]
        public Response4GetScheduleInfo GetScheduleInfo(Request4GetScheduleInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode hospIdNode = xmlDoc.CreateElement("hospitalId");
            hospIdNode.InnerText = request.HospitalId;
            root.AppendChild(hospIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("doctorId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode beginDateNode = xmlDoc.CreateElement("startDate");
            beginDateNode.InnerText = request.BeginDate;
            root.AppendChild(beginDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("endDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getscheduleinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetScheduleInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetScheduleInfo", requestXml, responseXml);

            responseXml = responseXml.Replace('“', '"');
            responseXml = responseXml.Replace('”', '"');
            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetScheduleInfo();
            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;
            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.ScheduleList = new List<Response4GetScheduleInfoSubScheduleInfo>();
                var nodes = xmlDoc.SelectNodes("/res/scheduleList/scheduleInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var scheduleObj = new Response4GetScheduleInfoSubScheduleInfo();

                    var scheduleId = xNode.SelectSingleNode("scheduleId") == null ? "" : xNode.SelectSingleNode("scheduleId").InnerText;
                    var sourceType = xNode.SelectSingleNode("sourceType") == null ? "" : xNode.SelectSingleNode("sourceType").InnerText;
                    var deptId = xNode.SelectSingleNode("deptId") == null ? "" : xNode.SelectSingleNode("deptId").InnerText;
                    var deptName = xNode.SelectSingleNode("deptName") == null ? "" : xNode.SelectSingleNode("deptName").InnerText;
                    var doctorId = xNode.SelectSingleNode("doctorId") == null ? "" : xNode.SelectSingleNode("doctorId").InnerText;
                    var doctorName = xNode.SelectSingleNode("doctorName") == null ? "" : xNode.SelectSingleNode("doctorName").InnerText;
                    var title = xNode.SelectSingleNode("title") == null ? "" : xNode.SelectSingleNode("title").InnerText;
                    var regDate = xNode.SelectSingleNode("regDate") == null ? "" : xNode.SelectSingleNode("regDate").InnerText;
                    var isHalt = xNode.SelectSingleNode("isHalt") == null ? "" : xNode.SelectSingleNode("isHalt").InnerText;
                    var timeSlice = xNode.SelectSingleNode("timeSlice") == null ? "" : xNode.SelectSingleNode("timeSlice").InnerText;
                    var startTime = xNode.SelectSingleNode("startTime") == null ? "" : xNode.SelectSingleNode("startTime").InnerText;
                    var endTime = xNode.SelectSingleNode("endTime") == null ? "" : xNode.SelectSingleNode("endTime").InnerText;
                    var totalCount = xNode.SelectSingleNode("totalCount") == null ? "" : xNode.SelectSingleNode("totalCount").InnerText;
                    var leaveCount = xNode.SelectSingleNode("leaveCount") == null ? "" : xNode.SelectSingleNode("leaveCount").InnerText;
                    var isTimeFlag = xNode.SelectSingleNode("isTimeFlag") == null ? "" : xNode.SelectSingleNode("isTimeFlag").InnerText;
                    var otherFee = xNode.SelectSingleNode("otherFee") == null ? "" : xNode.SelectSingleNode("otherFee").InnerText;
                    var regType = xNode.SelectSingleNode("regType") == null ? "" : xNode.SelectSingleNode("regType").InnerText;

                    var regFee = xNode.SelectSingleNode("regFee") == null ? "" : xNode.SelectSingleNode("regFee").InnerText;
                    var treatFee = xNode.SelectSingleNode("treatFee") == null ? "" : xNode.SelectSingleNode("treatFee").InnerText;

                    //var feeValue = regFee.ToDecimalOrDefault();
                    //var treatFeeValue = treatFee.ToDecimalOrDefault();

                    //if ((feeValue.CompareTo(0.00M) == 0) && (treatFeeValue.CompareTo(0.00M) == 0))
                    //{
                    //    continue;
                    //}

                    scheduleObj.ScheduleId = scheduleId;
                    scheduleObj.SourceType = sourceType;
                    scheduleObj.DeptId = deptId;
                    scheduleObj.DeptName = deptName;
                    scheduleObj.DoctorId = doctorId;
                    scheduleObj.DoctorName = doctorName;
                    scheduleObj.Title = title;
                    scheduleObj.RegDate = regDate;
                    scheduleObj.IsHalt = isHalt;
                    scheduleObj.TimeSlice = timeSlice;
                    scheduleObj.StartTime = startTime;
                    scheduleObj.EndTime = endTime;
                    scheduleObj.TotalCount = totalCount;
                    scheduleObj.LeaveCount = leaveCount;
                    scheduleObj.IsTimeFlag = isTimeFlag;
                    scheduleObj.RegType = regType;
                    scheduleObj.RegFee = regFee;
                    scheduleObj.TreatFee = treatFee;
                    scheduleObj.OtherFee = otherFee;

                    responseObj.ScheduleList.Add(scheduleObj);
                }
            }

            return responseObj;
        }

        /// <summary>
        /// 获取排班分时信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetTimeRegInfo")]
        public Response4GetTimeRegInfo GetTimeRegInfo(Request4GetTimeRegInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            hospitalIdNode.InnerText = request.HospitalId;
            root.AppendChild(hospitalIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("doctorId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode schedulIdNode = xmlDoc.CreateElement("schedulId");
            schedulIdNode.InnerText = request.SchedulId;
            root.AppendChild(schedulIdNode);

            XmlNode regDateNode = xmlDoc.CreateElement("regDate");
            regDateNode.InnerText = request.RegDate;
            root.AppendChild(regDateNode);

            XmlNode timeSliceNode = xmlDoc.CreateElement("timeSlice");
            timeSliceNode.InnerText = request.TimeSlice;
            root.AppendChild(timeSliceNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_gettimereginfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetTimeRegInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetTimeRegInfo", requestXml, responseXml);

            responseXml = responseXml.Replace('“', '"');
            responseXml = responseXml.Replace('”', '"');
            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetTimeRegInfo();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.TimeRegList = new List<Response4GetTimeRegInfoSubTimeRegInfo>();
                var nodes = xmlDoc.SelectNodes("/res/timeRegList/timeRegInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var timeRegObj = new Response4GetTimeRegInfoSubTimeRegInfo();
                    var startTime = xNode.SelectSingleNode("startTime").InnerText;
                    var endTime = xNode.SelectSingleNode("endTime").InnerText;
                    var totalCount = xNode.SelectSingleNode("totalCount").InnerText;
                    var leaveCount = xNode.SelectSingleNode("leaveCount").InnerText;
                    var sqNo = xNode.SelectSingleNode("sqNo").InnerText;
                    var czDeptCode = xNode.SelectSingleNode("cz_dept_code ").InnerText;

                    timeRegObj.StartTime = startTime;
                    timeRegObj.EndTime = endTime;
                    timeRegObj.TotalCount = totalCount;
                    timeRegObj.LeaveCount = leaveCount;
                    timeRegObj.SqNo = sqNo;
                    timeRegObj.czDeptCode = czDeptCode;

                    responseObj.TimeRegList.Add(timeRegObj);
                }
            }
            return responseObj;
        }


        /// <summary>
        /// 锁定号源
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ExeLockSource")]
        public Response4ExeLockSource ExeLockSource(Request4ExeLockSource request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);

            XmlNode scheduleIdNode = xmlDoc.CreateElement("scheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode sourceTypeNode = xmlDoc.CreateElement("sourceType");
            sourceTypeNode.InnerText = request.SourceType;
            root.AppendChild(sourceTypeNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("doctorId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode regDateNode = xmlDoc.CreateElement("regDate");
            regDateNode.InnerText = request.RegDate;
            root.AppendChild(regDateNode);

            XmlNode timeSliceNode = xmlDoc.CreateElement("timeSlice");
            timeSliceNode.InnerText = request.TimeSlice;
            root.AppendChild(timeSliceNode);

            XmlNode regTypeNode = xmlDoc.CreateElement("regType");
            regTypeNode.InnerText = request.RegType;
            root.AppendChild(regTypeNode);

            XmlNode startTimeNode = xmlDoc.CreateElement("startTime");
            startTimeNode.InnerText = request.StartTime;
            root.AppendChild(startTimeNode);

            XmlNode endTimeNode = xmlDoc.CreateElement("endTime");
            endTimeNode.InnerText = request.EndTime;
            root.AppendChild(endTimeNode);

            XmlNode regFeeNode = xmlDoc.CreateElement("regFee");
            regFeeNode.InnerText = request.RegFee;
            root.AppendChild(regFeeNode);

            XmlNode treatFeeNode = xmlDoc.CreateElement("treatFee");
            treatFeeNode.InnerText = request.TreatFee;
            root.AppendChild(treatFeeNode);

            XmlNode otherFeeNode = xmlDoc.CreateElement("otherFee");
            otherFeeNode.InnerText = request.OtherFee;
            root.AppendChild(otherFeeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_exelocksource(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeLockSource 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("ExeLockSource", requestXml, responseXml);

            responseXml = responseXml.Replace('“', '"');
            responseXml = responseXml.Replace('”', '"');
            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeLockSource();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            return responseObj;
        }

        /// <summary>
        /// 解锁号源
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ExeUnLockSource")]
        public Response4ExeUnLockSource ExeUnLockSource(Request4ExeUnLockSource request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_exeunlocksource(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeUnLockSource 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("ExeUnLockSource", requestXml, responseXml);

            responseXml = responseXml.Replace('“', '"');
            responseXml = responseXml.Replace('”', '"');
            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeUnLockSource();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            return responseObj;
        }

        /// <summary>
        /// 获取医生信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetDoctorInfo")]
        public Response4GetDoctorInfo GetDoctorInfo(Request4GetDoctorInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            hospitalIdNode.InnerText = request.HospitalId;
            root.AppendChild(hospitalIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("doctorId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getdoctorinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetDoctorInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("GetDoctorInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetDoctorInfo();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {
                responseObj.DoctorList = new List<Response4GetDoctorInfoSubDoctorInfo>();
                var nodes = xmlDoc.SelectNodes("/res/DoctorList/DoctorInfo");

                foreach (XmlNode xNode in nodes)
                {
                    var doctorInfoObj = new Response4GetDoctorInfoSubDoctorInfo();
                    var doctorId = xNode.SelectSingleNode("doctorId").InnerText;
                    var doctorName = xNode.SelectSingleNode("doctorName").InnerText;
                    var deptId = xNode.SelectSingleNode("deptId").InnerText;
                    var title = xNode.SelectSingleNode("Title").InnerText;
                    var fee = xNode.SelectSingleNode("Fee").InnerText;
                    var gender = xNode.SelectSingleNode("Gender").InnerText;
                    var desc = xNode.SelectSingleNode("Desc").InnerText;

                    doctorInfoObj.DoctorId = doctorId;
                    doctorInfoObj.DoctorName = doctorName;
                    doctorInfoObj.DeptId = deptId;
                    doctorInfoObj.Title = title;
                    doctorInfoObj.Fee = fee;
                    doctorInfoObj.Gender = gender;
                    doctorInfoObj.Desc = desc;

                    responseObj.DoctorList.Add(doctorInfoObj);
                }
            }
            return responseObj;
        }

        #region 患者建卡
        /// <summary>
        ///  建卡
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionName("CreateCard")]
        public CreateCardResponse CreateCard(CreateCardRequest request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode patNameNode = xmlDoc.CreateElement("patName");
            patNameNode.InnerText = request.Name;
            root.AppendChild(patNameNode);

            XmlNode patSexNode = xmlDoc.CreateElement("patSex");
            patSexNode.InnerText = request.Gender;
            root.AppendChild(patSexNode);

            XmlNode patBirthdayNode = xmlDoc.CreateElement("patBirthday");
            patBirthdayNode.InnerText = request.Birthdate;
            root.AppendChild(patBirthdayNode);

            XmlNode patAddrNode = xmlDoc.CreateElement("patAddr");
            patAddrNode.InnerText = request.Address;
            root.AppendChild(patAddrNode);

            XmlNode patIdNoNode = xmlDoc.CreateElement("patIdNo");
            patIdNoNode.InnerText = request.IdenNo;
            root.AppendChild(patIdNoNode);
            xmlDoc.AppendChild(root);

            XmlNode patTelNode = xmlDoc.CreateElement("patTel");
            patTelNode.InnerText = request.Phone;
            root.AppendChild(patTelNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_createcard(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 CreateCard 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("CreateCard", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new CreateCardResponse();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            node = xmlDoc.SelectSingleNode("/res/cardNo");
            var cardNo = node?.InnerText ?? "";
            responseObj.CardNo = cardNo;

            node = xmlDoc.SelectSingleNode("/res/cardType");
            var patientId = node?.InnerText ?? "";
            responseObj.PatientId = patientId;

            return responseObj;
        }
        #endregion

        /// <summary>
        /// 获取患者信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPatientInfo")]
        public Response4GetPatientInfo GetPatientInfo(Request4GetPatientInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode cardTypeNode = xmlDoc.CreateElement("cardtype");
            cardTypeNode.InnerText = request.CardType;
            root.AppendChild(cardTypeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getpatientinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPatientInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("GetPatientInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPatientInfo();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.PatientInfo = new Response4GetPatientInfoSubPatientInfo();
                var nodes = xmlDoc.SelectNodes("/res/patientInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var patientInfoObj = new Response4GetPatientInfoSubPatientInfo();
                    var patientId = xNode.SelectSingleNode("patientID").InnerText;
                    var inDeptNo = xNode.SelectSingleNode("InDeptNo").InnerText;
                    var name = xNode.SelectSingleNode("name").InnerText;
                    var gender = xNode.SelectSingleNode("Gender").InnerText;
                    var age = xNode.SelectSingleNode("Age").InnerText;
                    var birthDate = xNode.SelectSingleNode("Birthdate").InnerText;
                    var idenNo = xNode.SelectSingleNode("idenNo").InnerText;
                    var phone = xNode.SelectSingleNode("Phone").InnerText;
                    var feeType = xNode.SelectSingleNode("FeeType").InnerText;

                    patientInfoObj.PatientId = patientId;
                    patientInfoObj.InDeptNo = patientId;
                    patientInfoObj.Name = name;
                    patientInfoObj.Gender = gender;
                    patientInfoObj.Age = age;
                    patientInfoObj.Gender = gender;
                    patientInfoObj.Birthdate = birthDate;
                    patientInfoObj.IdenNo = idenNo;
                    patientInfoObj.Phone = phone;
                    patientInfoObj.FeeType = feeType;

                    responseObj.PatientInfo = patientInfoObj;
                }
            }

            return responseObj;
        }

        /// <summary>
        /// 预约(无)
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ExeAppoint")]
        public Response4ExeAppoint ExeAppoint(Request4ExeAppoint request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("Cardno");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode orderIdNode = xmlDoc.CreateElement("OrderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                //responseXml = wsClient.bkcloud_exeappoint(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeAppoint 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("ExeAppoint", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeAppoint();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            return responseObj;
        }

        /// <summary>
        /// 取消预约(无)
        /// </summary>
        /// <param name="request"></param>
        //[HttpPost]
        //[ActionName("CancelAppoint")]
        //public Response4CancelAppoint CancelAppoint(Request4CancelAppoint request)
        //{
        //    var wsClient = WsClientFactory.GetHisWsSoapClient();

        //    var xmlDoc = new XmlDocument();
        //    XmlNode root = xmlDoc.CreateElement("req");

        //    XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
        //    hospitalIdNode.InnerText = request.HospitalId;
        //    root.AppendChild(hospitalIdNode);

        //    XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
        //    orderIdNode.InnerText = request.OrderId;
        //    root.AppendChild(orderIdNode);
        //    xmlDoc.AppendChild(root);

        //    var requestXml = xmlDoc.InnerXml;

        //    var responseXml = "";
        //    try
        //    {
        //        //responseXml = wsClient.bkcloud_cancelappoint(requestXml);
        //        wsClient.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        wsClient.Abort();
        //        Logger.ErrorFormat("调用 CancelAppoint 失败，信息：{0}", JsonConvert.SerializeObject(ex));
        //        throw;
        //    }

        //    HospWsLogHelper.Log("CancelAppoint", requestXml, responseXml);


        //    xmlDoc = new XmlDocument();
        //    xmlDoc.LoadXml(responseXml);

        //    var responseObj = new Response4CancelAppoint();

        //    var node = xmlDoc.SelectSingleNode("/res/resultCode");
        //    var resultCode = node == null ? "" : node.InnerText;

        //    node = xmlDoc.SelectSingleNode("/res/resultDesc");
        //    var resultDesc = node == null ? "" : node.InnerText;

        //    responseObj.ResultCode = resultCode;
        //    responseObj.ResultDesc = resultDesc;

        //    return responseObj;
        //}

        /// <summary>
        /// 获取订单状态
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegOrderStatus")]
        public Response4GetOrderStatus GetOrderStatus(Request4GetOrderStatus request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getregorderstatus(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetRegOrderStatus 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetRegOrderStatus", requestXml, responseXml);


            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetOrderStatus();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/status");
            var status = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            responseObj.Status = status;

            var xNode = xmlDoc.SelectSingleNode("/res");
            if (resultCode == "0"|| status == "2") //已支付
            {
                xNode = xNode.SelectSingleNode("regInfo");

                var rcptNo = xNode.SelectSingleNode("rcptNo") == null ? "" : xNode.SelectSingleNode("rcptNo").InnerText;
                var regNo = xNode.SelectSingleNode("regNo") == null ? "" : xNode.SelectSingleNode("regNo").InnerText;
                var visitNo = xNode.SelectSingleNode("visitNo") == null ? "" : xNode.SelectSingleNode("visitNo").InnerText;
                var deptName = xNode.SelectSingleNode("deptName") == null ? "" : xNode.SelectSingleNode("deptName").InnerText;
                var doctorName = xNode.SelectSingleNode("doctorName") == null ? "" : xNode.SelectSingleNode("doctorName").InnerText;

                var regDate = xNode.SelectSingleNode("regDate") == null ? "" : xNode.SelectSingleNode("regDate").InnerText;
                var timeSlice = xNode.SelectSingleNode("timeSlice") == null ? "" : xNode.SelectSingleNode("timeSlice").InnerText;
                var regType = xNode.SelectSingleNode("regType") == null ? "" : xNode.SelectSingleNode("regType").InnerText;
                var patientName = xNode.SelectSingleNode("patientName") == null ? "" : xNode.SelectSingleNode("patientName").InnerText;
                var startTime = xNode.SelectSingleNode("startTime") == null ? "" : xNode.SelectSingleNode("startTime").InnerText;

                var endTime = xNode.SelectSingleNode("endTime") == null ? "" : xNode.SelectSingleNode("endTime").InnerText;
                var address = xNode.SelectSingleNode("address") == null ? "" : xNode.SelectSingleNode("address").InnerText;

                var regInfo = new Response4GetOrderStatusSubRegInfo();

                regInfo.DeptName = deptName;
                regInfo.DoctorName = doctorName;
                regInfo.RegDate = regDate;
                regInfo.TimeSlice = timeSlice;
                regInfo.RegType = regType;

                regInfo.PatientName = patientName;
                regInfo.RegNo = regNo;
                regInfo.VisitNo = visitNo;
                regInfo.StartTime = startTime;
                regInfo.EndTime = endTime;

                regInfo.Address = address;
                regInfo.RcptNo = rcptNo;

                responseObj.RegInfo = regInfo;
            }

            return responseObj;
        }

        /// <summary>
        /// 挂号(无)
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ExeRegister")]
        public Response4ExeRegister ExeRegister(Request4ExeRegister request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);            

            XmlNode payTypeNode = xmlDoc.CreateElement("payType");
            payTypeNode.InnerText = request.PayType;
            root.AppendChild(payTypeNode);

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode payCountNode = xmlDoc.CreateElement("payCount");
            payCountNode.InnerText = request.PayCount;
            root.AppendChild(payCountNode);

            XmlNode transNoNode = xmlDoc.CreateElement("transNo");
            transNoNode.InnerText = request.TransNo;
            root.AppendChild(transNoNode);

            XmlNode transTimeNode = xmlDoc.CreateElement("transTime");
            transTimeNode.InnerText = request.TransTime;
            root.AppendChild(transTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                //responseXml = wsClient.bkcloud_exeregister(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeRegister 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("ExeRegister", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeRegister();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;


            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {

                var xNode = xmlDoc.SelectSingleNode("/res");
                var deptName = xNode.SelectSingleNode("deptName").InnerText;
                var doctor = xNode.SelectSingleNode("doctor").InnerText;
                var regDate = xNode.SelectSingleNode("regDate").InnerText;
                var timeFlag = xNode.SelectSingleNode("timeSlice").InnerText;
                var regType = xNode.SelectSingleNode("regType").InnerText;
                var patientId = xNode.SelectSingleNode("patientId").InnerText;
                var name = xNode.SelectSingleNode("name").InnerText;
                var regNo = xNode.SelectSingleNode("regNo").InnerText;
                var visitNo = xNode.SelectSingleNode("visitNo").InnerText;
                var beginTime = xNode.SelectSingleNode("startTime").InnerText;
                var endTime = xNode.SelectSingleNode("endTime").InnerText;
                var address = xNode.SelectSingleNode("address").InnerText;

                responseObj.DeptName = deptName;
                responseObj.Doctor = doctor;
                responseObj.RegDate = regDate;
                responseObj.TimeFlag = timeFlag;
                responseObj.RegType = regType;
                responseObj.PatientId = patientId;
                responseObj.Name = name;
                responseObj.RegNo = regNo;
                responseObj.VisitNo = visitNo;
                responseObj.BeginTime = beginTime;
                responseObj.EndTime = endTime;
                responseObj.Address = address;
            }
            return responseObj;
        }

        /// <summary>
        /// 预约取号挂号
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegInfo")]
        public Response4ExeResSourceRegister ExeResSourceRegister(Request4ExeResSourceRegister request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);            

            XmlNode orderTypeNode = xmlDoc.CreateElement("orderType");
            orderTypeNode.InnerText = request.OrderType;
            root.AppendChild(orderTypeNode);

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode payCountNode = xmlDoc.CreateElement("payCount");
            payCountNode.InnerText = request.PayCount;
            root.AppendChild(payCountNode);

            XmlNode transNoNode = xmlDoc.CreateElement("transNo");
            transNoNode.InnerText = request.TransNo;
            root.AppendChild(transNoNode);

            XmlNode transTimeNode = xmlDoc.CreateElement("transTime");
            transTimeNode.InnerText = request.TransTime;
            root.AppendChild(transTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getreginfo(requestXml);

                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetRegInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetRegInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeResSourceRegister();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                var xNode = xmlDoc.SelectSingleNode("/res/regInfo");

                var regNo = xNode.SelectSingleNode("regNo").InnerText;
                var visitNo = xNode.SelectSingleNode("visitNo").InnerText;
                var rcptNo = xNode.SelectSingleNode("rcptNo").InnerText;
                var deptName = xNode.SelectSingleNode("deptName").InnerText;
                var doctorName = xNode.SelectSingleNode("doctorName").InnerText;

                var regType = xNode.SelectSingleNode("regType").InnerText;
                var regDate = xNode.SelectSingleNode("regDate").InnerText;
                var timeSlice = xNode.SelectSingleNode("timeSlice").InnerText;
                var startTime = xNode.SelectSingleNode("startTime").InnerText;
                var endTime = xNode.SelectSingleNode("endTime").InnerText;

                var patientName = xNode.SelectSingleNode("patientName").InnerText;
                var address = xNode.SelectSingleNode("address").InnerText;

                Response4ExeResSourceRegisterSubRegInfo regInfo = new Response4ExeResSourceRegisterSubRegInfo();

                regInfo.RegNo = regNo;
                regInfo.VisitNo = visitNo;
                regInfo.RcptNo = rcptNo;
                regInfo.DeptName = deptName;
                regInfo.DoctorName = doctorName;

                regInfo.RegType = regType;
                regInfo.RegDate = regDate;
                regInfo.TimeSlice = timeSlice;
                regInfo.StartTime = startTime;
                regInfo.EndTime = endTime;

                regInfo.Address = address;
                regInfo.PatientName = patientName;

                responseObj.RegInfo = regInfo;
            }
            return responseObj;
        }

        /// <summary>
        /// 预约报到(无)
        /// </summary>
        /// <param name="request"></param>

        [HttpPost]
        [ActionName("ExeAppointSignin")]
        public Response4ExeAppointSignin ExeAppointSignin(Request4ExeAppointSignin request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode orderIdNode = xmlDoc.CreateElement("orderId");
            orderIdNode.InnerText = request.OrderId;
            root.AppendChild(orderIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
               // responseXml = wsClient.bkcloud_exeappointsignin(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeAppointSignin 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("ExeAppointSignin", requestXml, responseXml);


            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExeAppointSignin();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            return responseObj;
        }


        /// <summary>
        /// 取号查询(无)
        /// </summary>
        /// <param name="request"></param>
        /// 

        [HttpPost]
        [ActionName("GetResSource")]
        public Response4GetResSource GetResSource(Request4GetResSource request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);            

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                //  responseXml = wsClient.GetResSource(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExeAppointSignin 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("ExeAppointSignin", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetResSource();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;


            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {
                responseObj.ScheduleList = new List<Response4GetResSourceSubResSourceInfo>();
                var nodes = xmlDoc.SelectNodes("/res/ScheduleList/ResSourceInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var scheduleObj = new Response4GetResSourceSubResSourceInfo();

                    var deptId = xNode.SelectSingleNode("DeptId").InnerText;
                    var deptName = xNode.SelectSingleNode("DeptName").InnerText;
                    var doctorId = xNode.SelectSingleNode("DoctorId").InnerText;
                    var doctorName = xNode.SelectSingleNode("DoctorName").InnerText;
                    var regType = xNode.SelectSingleNode("RegType").InnerText;
                    var regDate = xNode.SelectSingleNode("RegDate").InnerText;
                    var regNo = xNode.SelectSingleNode("RegNo").InnerText;
                    var timeSlice = xNode.SelectSingleNode("TimeSlice").InnerText;
                    var startTime = xNode.SelectSingleNode("StartTime").InnerText;
                    var endTime = xNode.SelectSingleNode("EndTime").InnerText;
                    var fee = xNode.SelectSingleNode("Fee").InnerText;
                    var treatFee = xNode.SelectSingleNode("TreatFee").InnerText;
                    var otherFee = xNode.SelectSingleNode("OtherFee").InnerText;

                    scheduleObj.DeptId = deptId;
                    scheduleObj.DeptName = deptName;
                    scheduleObj.DoctorId = doctorId;
                    scheduleObj.DoctorName = doctorName;
                    scheduleObj.RegDate = regDate;
                    scheduleObj.TimeSlice = timeSlice;
                    scheduleObj.StartTime = startTime;
                    scheduleObj.EndTime = endTime;
                    scheduleObj.RegType = regType;
                    scheduleObj.RegNo = regNo;
                    scheduleObj.Fee = fee;
                    scheduleObj.TreatFee = treatFee;
                    scheduleObj.OtherFee = otherFee;

                    responseObj.ScheduleList.Add(scheduleObj);
                }
            }
            return responseObj;
        }


        /// <summary>
        /// 获取用户队列信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetQueueInfo")]
        public Response4GetQueueInfo GetQueueInfo(Request4GetQueueInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode queueDateNode = xmlDoc.CreateElement("queueDate");
            queueDateNode.InnerText = request.QueueDate;
            root.AppendChild(queueDateNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getqueueinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetQueueInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetQueueInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetQueueInfo();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;


            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {

                responseObj.QueueList = new List<Response4GetQueueInfoSubQueueInfo>();
                var nodes = xmlDoc.SelectNodes("/res/Queuelist/QueueInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var queueInfoObj = new Response4GetQueueInfoSubQueueInfo();
                    var name = xNode.SelectSingleNode("Name").InnerText;
                    var state = xNode.SelectSingleNode("State").InnerText;
                    var deptId = xNode.SelectSingleNode("DeptId").InnerText;
                    var deptName = xNode.SelectSingleNode("DeptName").InnerText;
                    var doctorId = xNode.SelectSingleNode("DoctorId").InnerText;
                    var doctorName = xNode.SelectSingleNode("DcotorName").InnerText;
                    var patientName = xNode.SelectSingleNode("PatientName").InnerText;
                    var regNo = xNode.SelectSingleNode("RegNo").InnerText;
                    var foreNum = xNode.SelectSingleNode("ForeNum").InnerText;
                    var unpayNum = xNode.SelectSingleNode("UnPayNum").InnerText;
                    var cardNo = xNode.SelectSingleNode("CardNo").InnerText;
                    //var regType = xNode.SelectSingleNode("regType").InnerText;
                    //var curNo = xNode.SelectSingleNode("curNo").InnerText;

                    queueInfoObj.Name = name;
                    queueInfoObj.State = state;
                    queueInfoObj.DeptId = deptId;
                    queueInfoObj.DeptName = deptName;
                    queueInfoObj.DoctorId = doctorId;
                    queueInfoObj.DoctorName = doctorName;
                    queueInfoObj.PatientName = patientName;
                    queueInfoObj.RegNo = regNo;
                    queueInfoObj.ForeNum = foreNum;
                    //queueInfoObj.CurNo = curNo;
                    queueInfoObj.UnpayNum = unpayNum;
                    queueInfoObj.CardNo = cardNo;
                   // queueInfoObj.RegType = regType;

                    responseObj.QueueList.Add(queueInfoObj);
                }
            }
            return responseObj;

        }

        /// <summary>
        /// 获取缴费单列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPrescriptionList")]
        public Response4GetPrescriptionList GetPrescriptionList(Request4GetPrescriptionList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = paramObject.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;

            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getprescriptionlist(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPrescriptionList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }
            HospWsLogHelper.Log("GetPrescriptionList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPrescriptionList();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.PrescList = new List<Response4GetPrescriptionListSubPrescInfo>();
                var nodes = xmlDoc.SelectNodes("/res/PrescList/PrescInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var prescInfoObj = new Response4GetPrescriptionListSubPrescInfo();
                    var clinicNo = xNode.SelectSingleNode("ClinicNo").InnerText;
                    var prescMoney = xNode.SelectSingleNode("PrescMoney").InnerText;
                    var orderDept = xNode.SelectSingleNode("OrderDept").InnerText;
                    var orderDate = xNode.SelectSingleNode("OrderDate").InnerText;
                    var orderDoctor = xNode.SelectSingleNode("orderDoctor").InnerText;

                    prescInfoObj.ClinicNo = clinicNo;
                    prescInfoObj.PrescMoney = prescMoney;
                    prescInfoObj.OrderDept = orderDept;
                    prescInfoObj.OrderDate = orderDate;
                    prescInfoObj.OrderDoctor = orderDoctor;

                    responseObj.PrescList.Add(prescInfoObj);
                }
            }

            return responseObj;
        }


        /// <summary>
        /// 获取缴费单内容（明细）
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPrescriptionDetail")]
        public Response4GetPrescriptionDetail GetPrescriptionDetail(Request4GetPrescriptionDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode prescNoNode = xmlDoc.CreateElement("clinicNo");
            prescNoNode.InnerText = request.PrescNo;
            root.AppendChild(prescNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getprescriptiondetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPrescriptionDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetPrescriptionDetail", requestXml, responseXml);
            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPrescriptionDetail();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.PrescItemList = new List<Response4GetPrescriptionDetailSubPrescItemInfo>();
                var nodes = xmlDoc.SelectNodes("/res/PrescItemList/PrescItem");
                foreach (XmlNode xNode in nodes)
                {
                    var prescItemInfoObj = new Response4GetPrescriptionDetailSubPrescItemInfo();
                    var name = xNode.SelectSingleNode("ItemName").InnerText;
                    var account = xNode.SelectSingleNode("Account").InnerText;
                    var itemPrice = xNode.SelectSingleNode("ItemPrice").InnerText;
                    var unit = xNode.SelectSingleNode("unit").InnerText;
                    var money = xNode.SelectSingleNode("Money").InnerText;
                    var type = xNode.SelectSingleNode("Type").InnerText;

                    prescItemInfoObj.ItemName = name;
                    prescItemInfoObj.Account = account;
                    prescItemInfoObj.ItemPrice = itemPrice;
                    prescItemInfoObj.Unit = unit;
                    prescItemInfoObj.Money = money;
                    prescItemInfoObj.Type = type;

                    responseObj.PrescItemList.Add(prescItemInfoObj);
                }
            }
            return responseObj;
        }

        /// <summary>
        /// 获取缴费单状态
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPayStatus")]
        public Response4GetPayStatus GetPayStatus(Request4GetPayStatus request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode clinicNoNode = xmlDoc.CreateElement("clinicNo");
            clinicNoNode.InnerText = request.ClinicNo;
            root.AppendChild(clinicNoNode);

            XmlNode orderNoNode = xmlDoc.CreateElement("orderNo");
            orderNoNode.InnerText = request.OrderNo;
            root.AppendChild(orderNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getpaystatus(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPayStatus 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetPayStatus", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPayStatus();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {
                responseObj.Status = xmlDoc.SelectSingleNode("/res/Status") == null ? "" : xmlDoc.SelectSingleNode("/res/Status").InnerText;

                node = xmlDoc.SelectSingleNode("/res/virRcptNo"); //虚拟发票号
                var virRcptNo = node == null ? "" : node.InnerText;
                responseObj.VirRcptNo = virRcptNo;

                node = xmlDoc.SelectSingleNode("/res/realRcptNo"); //真实发票号
                var realRcptNo = node == null ? "" : node.InnerText;
                responseObj.RealRcptNo = realRcptNo;

                responseObj.DisWinList = new List<Response4GetPayStatusSubDisWinInfo>();
                responseObj.CMDisWinList = new List<Response4GetPayStatusSubDisWinInfo>();
                responseObj.AddressList = new List<Response4GetPayStatusSubAddressInfo>();
                responseObj.CLDisWinList = new List<Response4GetPayStatusSubDisWinInfo>();

                #region 西药发药地址
                var nodes = xmlDoc.SelectNodes("/res/disWinList/disWinInfo");
                if (nodes != null)
                {
                    foreach (XmlNode xNode in nodes)
                    {
                        var disWinInfObj = new Response4GetPayStatusSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText;

                        disWinInfObj.VisitNo = visitNo;
                        disWinInfObj.DisWinAdd = disWinAdd;
                        disWinInfObj.DisWin = disWin;
                        disWinInfObj.MedicineName = medicineName;

                        responseObj.DisWinList.Add(disWinInfObj);
                    }
                }
                #endregion 

                #region  (中药发药信息)
                var winNodes = xmlDoc.SelectNodes("/res/cmDisWinList/cmDisWinInfo");
                if (winNodes != null)
                {
                    foreach (XmlNode xNode in winNodes)
                    {
                        var disWinInfoObj = new Response4GetPayStatusSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;//窗体
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //药名

                        //disWinInfoObj.RcptNo = rcptNo;
                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.CMDisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region (检查地址)
                var addNodes = xmlDoc.SelectNodes("/res/addressList/addressInfo");
                if (addNodes != null)
                {
                    foreach (XmlNode xNode in addNodes)
                    {
                        var addressInfoObj = new Response4GetPayStatusSubAddressInfo();

                        var examId = xNode.SelectSingleNode("examId").InnerText;
                        var examName = xNode.SelectSingleNode("examName").InnerText;
                        var location = xNode.SelectSingleNode("Location").InnerText;
                        var fetchTime = xNode.SelectSingleNode("fetchTime").InnerText; //药名

                        //disWinInfoObj.RcptNo = rcptNo;
                        addressInfoObj.ExamId = examId;
                        addressInfoObj.ExamName = examName;
                        addressInfoObj.Location = location;
                        addressInfoObj.FetchTime = fetchTime;

                        responseObj.AddressList.Add(addressInfoObj);
                    }
                }
                #endregion 

                #region 材料地址
                var clNodes = xmlDoc.SelectNodes("/res/clDisWinList/clDisWinInfo");
                if (nodes != null)
                {
                    foreach (XmlNode xNode in nodes)
                    {
                        var disWinInfObj = new Response4GetPayStatusSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText;

                        disWinInfObj.VisitNo = visitNo;
                        disWinInfObj.DisWinAdd = disWinAdd;
                        disWinInfObj.DisWin = disWin;
                        disWinInfObj.MedicineName = medicineName;

                        responseObj.DisWinList.Add(disWinInfObj);
                    }
                }
                #endregion

            }

            return responseObj;
        }
        /// <summary>
        /// 缴费
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ExePrescriptionPay")]
        public Response4ExePrescriptionPay ExePrescriptionPay(Request4ExePrescriptionPay request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();

            //
            //<req><cardNo>027</cardNo><sumFee>74.48</sumFee><prescList><prescInfo><prescNo>623231</prescNo><prescMoney>74.48</prescMoney></prescInfo></prescList><transTime>2014-11-11</transTime><transNo>20001</transNo></req>
            //

            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            //增加orderNo 
            XmlNode orderNoNode = xmlDoc.CreateElement("orderNo");
            orderNoNode.InnerText = request.OrderNo;
            root.AppendChild(orderNoNode);

            XmlNode prescNoNode = xmlDoc.CreateElement("clinicNo");
            prescNoNode.InnerText = request.PrescNo;
            root.AppendChild(prescNoNode);

            XmlNode sumFeeNode = xmlDoc.CreateElement("zfy");
            sumFeeNode.InnerText = request.SumFee;
            root.AppendChild(sumFeeNode);

            XmlNode transNoNode = xmlDoc.CreateElement("transNo");
            transNoNode.InnerText = request.TransNo;
            root.AppendChild(transNoNode);

            XmlNode transTimeNode = xmlDoc.CreateElement("transTime");
            transTimeNode.InnerText = request.TransTime;
            root.AppendChild(transTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;


            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_exeprescriptionpay(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 ExePrescriptionPay 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("ExePrescriptionPay", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4ExePrescriptionPay();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                node = xmlDoc.SelectSingleNode("/res/virRcptNo"); //虚拟发票号
                var virRcptNo = node == null ? "" : node.InnerText;
                responseObj.VirRcptNo = virRcptNo;

                node = xmlDoc.SelectSingleNode("/res/realRcptNo"); //真实发票号
                var realRcptNo = node == null ? "" : node.InnerText;
                responseObj.RealRcptNo = realRcptNo;

                responseObj.DisWinList = new List<Response4ExePrescriptionPaySubDisWinInfo>();
                responseObj.CMDisWinList = new List<Response4ExePrescriptionPaySubDisWinInfo>();
                responseObj.AddressList = new List<Response4ExePrescriptionPaySubAddressInfo>();
                responseObj.CLDisWinList = new List<Response4ExePrescriptionPaySubDisWinInfo>();

                #region 西药发药信息
                var nodes = xmlDoc.SelectNodes("/res/disWinList/disWinInfo");
                if (nodes != null)
                {
                    foreach (XmlNode xNode in nodes)
                    {
                        var disWinInfoObj = new Response4ExePrescriptionPaySubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //药名

                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.DisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region  (中药发药信息)
                var winNodes = xmlDoc.SelectNodes("/res/cmDisWinList/cmDisWinInfo");
                if (winNodes != null)
                {
                    foreach (XmlNode xNode in winNodes)
                    {
                        var disWinInfoObj = new Response4ExePrescriptionPaySubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;//窗体
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //药名

                        //disWinInfoObj.RcptNo = rcptNo;
                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.CMDisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region (检查地址)
                var addNodes = xmlDoc.SelectNodes("/res/addressList/addressInfo");
                if (addNodes != null)
                {
                    foreach (XmlNode xNode in addNodes)
                    {
                        var addressInfoObj = new Response4ExePrescriptionPaySubAddressInfo();

                        var examId = xNode.SelectSingleNode("examId").InnerText;
                        var examName = xNode.SelectSingleNode("examName").InnerText;
                        var location = xNode.SelectSingleNode("Location").InnerText;
                        var fetchTime = xNode.SelectSingleNode("fetchTime").InnerText; //药名

                        addressInfoObj.ExamId = examId;
                        addressInfoObj.ExamName = examName;
                        addressInfoObj.Location = location;
                        addressInfoObj.FetchTime = fetchTime;

                        responseObj.AddressList.Add(addressInfoObj);
                    }
                }
                #endregion

                #region 材料地址
                var clNodes = xmlDoc.SelectNodes("/res/clDisWinList/cldisWinInfo");
                if (clNodes != null)
                {
                    foreach (XmlNode xNode in clNodes)
                    {
                        var disWinInfoObj = new Response4ExePrescriptionPaySubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;//窗体
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //项目名称

                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.CLDisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion
            }
            return responseObj;
        }

        /// <summary>
        /// 获取历次缴费单列表(包括现场和微信等)
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPayRecords")]
        public Response4GetPayRecords GetPayRecords(Request4GetPayRecords request)
        {
            Logger.ErrorFormat("调用 获取历次缴费单列表 失败，信息：{0}", JsonConvert.SerializeObject(request));
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode startDateNode = xmlDoc.CreateElement("startDate");
            startDateNode.InnerText = request.BeginDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("endDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getrecords(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPayRecords 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetPayRecords", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPayRecords();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.RecordList = new List<Response4GetPayRecordsSubRecordInfo>();
                var nodes = xmlDoc.SelectNodes("/res/recordList/recordInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var prescInfoObj = new Response4GetPayRecordsSubRecordInfo();
                    var clinicNo = xNode.SelectSingleNode("clinicNo").InnerText;
                    var prescMoney = xNode.SelectSingleNode("prescMoney").InnerText;
                    var orderDept = xNode.SelectSingleNode("orderDept").InnerText;
                    var orderDate = xNode.SelectSingleNode("orderDate").InnerText;
                    var typeId = xNode.SelectSingleNode("typeId").InnerText;
                    var orderNo = xNode.SelectSingleNode("orderNo").InnerText;
                    var payDate = xNode.SelectSingleNode("payDate").InnerText;
                    var orderDoctor = xNode.SelectSingleNode("orderDoctor").InnerText;
                    var invoStatus = xNode.SelectSingleNode("invoStatus").InnerText;

                    prescInfoObj.clinicNo = clinicNo;
                    prescInfoObj.prescMoney = prescMoney;
                    prescInfoObj.orderDept = orderDept;
                    prescInfoObj.orderDate = orderDate;
                    prescInfoObj.typeId = typeId;
                    prescInfoObj.orderNo = orderNo.ToUpper();//转成大写
                    prescInfoObj.payDate = payDate;
                    prescInfoObj.orderDoctor = orderDoctor;
                    prescInfoObj.invoStatus = invoStatus;

                    responseObj.RecordList.Add(prescInfoObj);
                }
            }
            else {

            }

            return responseObj;
        }


        /// <summary>
        /// 获取历次缴费单内容（明细）
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPayRecordsDetail")]
        public Response4GetPayRecordsDetail GetPayRecordsDetail(Request4GetPayRecordsDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode orderNoNode = xmlDoc.CreateElement("OrderNo");
            orderNoNode.InnerText = request.OrderNo;
            root.AppendChild(orderNoNode);

            XmlNode prescNoNode = xmlDoc.CreateElement("ClinicNo");
            prescNoNode.InnerText = request.PrescNo;
            root.AppendChild(prescNoNode);

            XmlNode cardTypeNode = xmlDoc.CreateElement("CardType");
            cardTypeNode.InnerText = request.CardType;
            root.AppendChild(cardTypeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getpayrecordsdetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetPayRecordsDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetPayRecordsDetail", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetPayRecordsDetail();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.PrescItemList = new List<Response4GetPayRecordsDetailSubPrescItemInfo>();
                responseObj.DisWinList = new List<Response4GetPayRecordsDetailSubDisWinInfo>();
                responseObj.CMDisWinList = new List<Response4GetPayRecordsDetailSubDisWinInfo>();
                responseObj.AddressList = new List<Response4GetPayRecordsDetailSubAddressInfo>();
                responseObj.CLDisWinList = new List<Response4GetPayRecordsDetailSubDisWinInfo>();

                node = xmlDoc.SelectSingleNode("/res/virRcptNo"); //虚拟发票号
                var virRcptNo = node == null ? "" : node.InnerText;
                responseObj.VirRcptNo = virRcptNo;

                node = xmlDoc.SelectSingleNode("/res/realRcptNo"); //真实发票号
                var realRcptNo = node == null ? "" : node.InnerText;
                responseObj.RealRcptNo = realRcptNo;

                node = xmlDoc.SelectSingleNode("/res/invoStatus"); //真实发票状态
                var invoStatus = node == null ? "" : node.InnerText;
                responseObj.InvoStatus = invoStatus;

                #region 西药发药信息
                var nodes = xmlDoc.SelectNodes("/res/disWinList/disWinInfo");
                if (nodes != null)
                {
                    foreach (XmlNode xNode in nodes)
                    {
                        var disWinInfoObj = new Response4GetPayRecordsDetailSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //药名

                        //disWinInfoObj.RcptNo = rcptNo;
                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.DisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region  (中药发药信息)
                var winNodes = xmlDoc.SelectNodes("/res/cmDisWinList/cmDisWinInfo");
                if (winNodes != null)
                {
                    foreach (XmlNode xNode in winNodes)
                    {
                        var disWinInfoObj = new Response4GetPayRecordsDetailSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;//窗体
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //药名

                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.CMDisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region (检查地址)

                var addNodes = xmlDoc.SelectNodes("/res/addressList/addressInfo");
                if (addNodes != null)
                {
                    foreach (XmlNode xNode in addNodes)
                    {
                        var addressInfoObj = new Response4GetPayRecordsDetailSubAddressInfo();

                        var examId = xNode.SelectSingleNode("examId").InnerText;
                        var examName = xNode.SelectSingleNode("examName").InnerText;
                        var location = xNode.SelectSingleNode("Location").InnerText;
                        var fetchTime = xNode.SelectSingleNode("fetchTime").InnerText; //药名

                        addressInfoObj.ExamId = examId;
                        addressInfoObj.ExamName = examName;
                        addressInfoObj.Location = location;
                        addressInfoObj.FetchTime = fetchTime;

                        responseObj.AddressList.Add(addressInfoObj);
                    }
                }
                #endregion

                #region  (材料信息)
                var clNodes = xmlDoc.SelectNodes("/res/clDisWinList/clDisWinInfo");
                if (clNodes != null)
                {
                    foreach (XmlNode xNode in clNodes)
                    {
                        var disWinInfoObj = new Response4GetPayRecordsDetailSubDisWinInfo();
                        var visitNo = xNode.SelectSingleNode("visitNo ").InnerText;
                        var disWinAdd = xNode.SelectSingleNode("disWinAdd").InnerText;
                        var disWin = xNode.SelectSingleNode("disWin").InnerText;//窗体
                        var medicineName = xNode.SelectSingleNode("medicineName").InnerText; //项目名

                        disWinInfoObj.VisitNo = visitNo;
                        disWinInfoObj.DisWinAdd = disWinAdd;
                        disWinInfoObj.DisWin = disWin;
                        disWinInfoObj.MedicineName = medicineName;

                        responseObj.CLDisWinList.Add(disWinInfoObj);
                    }
                }
                #endregion

                #region 处方项
                var prescNodes = xmlDoc.SelectNodes("/res/PrescItemList/PrescItem");
                if (prescNodes != null)
                {
                    foreach (XmlNode xNode in prescNodes)
                    {
                        var prescItemInfoObj = new Response4GetPayRecordsDetailSubPrescItemInfo();
                        var name = xNode.SelectSingleNode("ItemName").InnerText;
                        var account = xNode.SelectSingleNode("Account").InnerText;
                        var itemPrice = xNode.SelectSingleNode("ItemPrice").InnerText;
                        var unit = xNode.SelectSingleNode("unit").InnerText;
                        var money = xNode.SelectSingleNode("Money").InnerText;
                        var type = xNode.SelectSingleNode("Type").InnerText;

                        prescItemInfoObj.ItemName = name;
                        prescItemInfoObj.Account = account;
                        prescItemInfoObj.ItemPrice = itemPrice;
                        prescItemInfoObj.Unit = unit;
                        prescItemInfoObj.Money = money;
                        prescItemInfoObj.Type = type;

                        responseObj.PrescItemList.Add(prescItemInfoObj);
                    }
                }
                #endregion

            }
            return responseObj;
        }

        /// <summary>
        /// 获取检验、检查单列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetExamInfo")]
        public Response4GetExamInfo GetExamInfo(Request4GetExamInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode itemTypeNode = xmlDoc.CreateElement("itemType");
            itemTypeNode.InnerText = request.ItemType;
            root.AppendChild(itemTypeNode);

            XmlNode beginDateNode = xmlDoc.CreateElement("BeginDate");
            beginDateNode.InnerText = request.BeginDate;
            root.AppendChild(beginDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getexaminfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetExamInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetExamInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetExamInfo();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;
            if (resultCode == "0")
            {
                responseObj.ExamList = new List<Response4GetExamInfoSubExamInfo>();
                var nodes = xmlDoc.SelectNodes("/res/ExamList/ExamInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var examInfoObj = new Response4GetExamInfoSubExamInfo();
                    var examId = xNode.SelectSingleNode("ExamID").InnerText;
                    var examName = xNode.SelectSingleNode("ExamName").InnerText;
                    var examDate = xNode.SelectSingleNode("ExamDate").InnerText;
                    var cardNo = xNode.SelectSingleNode("CardNo").InnerText;
                    var patientID = xNode.SelectSingleNode("PatientID").InnerText;
                    var patientName = xNode.SelectSingleNode("PatientName").InnerText;
                    var patientSex = xNode.SelectSingleNode("PatientSex").InnerText;
                    var status = xNode.SelectSingleNode("Status").InnerText;
                    var examType = xNode.SelectSingleNode("examType").InnerText;
                    var reportDate = xNode.SelectSingleNode("reportDate").InnerText;
                    var fetchAddress = xNode.SelectSingleNode("fetchAddress").InnerText;


                    examInfoObj.ExamID = examId;
                    examInfoObj.ExamName = examName;
                    examInfoObj.ExamDate = examDate;
                    examInfoObj.CardNo = cardNo;
                    examInfoObj.PatientID = patientID;
                    examInfoObj.PatientName = patientName;
                    examInfoObj.PatientSex = patientSex;
                    examInfoObj.Status = status;

                    examInfoObj.ReportDate = reportDate;
                    examInfoObj.FetchAddress = fetchAddress;
                    examInfoObj.ExamType = examType;

                    responseObj.ExamList.Add(examInfoObj);
                }
            }
            return responseObj;
        }

        /// <summary>
        /// 获取检查单，检验单闽西
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetExamDetail")]
        public Response4GetExamDetail GetExamDetail(Request4GetExamDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode cardNoNode = xmlDoc.CreateElement("cardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode itemTypeNode = xmlDoc.CreateElement("itemType");
            itemTypeNode.InnerText = request.ItemType;
            root.AppendChild(itemTypeNode);

            XmlNode examIdNode = xmlDoc.CreateElement("examId");
            examIdNode.InnerText = request.ExamId;
            root.AppendChild(examIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_getexamdetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetExamDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetExamDetail", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetExamDetail();

            var node = xmlDoc.SelectSingleNode("/res/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/ResultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            responseObj.ResultCode = resultCode;
            responseObj.ResultDesc = resultDesc;

            if (resultCode == "0")
            {
                responseObj.ExamItemList = new List<Response4GetExamDetailSubExamItemInfo>();
                var nodes = xmlDoc.SelectNodes("/res/ExamItemList/ExamItemInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var examItemInfoObj = new Response4GetExamDetailSubExamItemInfo();
                    var itemNo = xNode.SelectSingleNode("ItemNo") == null ? "" : xNode.SelectSingleNode("ItemNo").InnerText;
                    var itemDate = xNode.SelectSingleNode("ItemDate") == null ? "" : xNode.SelectSingleNode("ItemDate").InnerText;
                    var examItemName = xNode.SelectSingleNode("ExamItemName") == null ? "" : xNode.SelectSingleNode("ExamItemName").InnerText;
                    var prompt = xNode.SelectSingleNode("Prompt") == null ? "" : xNode.SelectSingleNode("Prompt").InnerText;
                    var content = xNode.SelectSingleNode("Content") == null ? "" : xNode.SelectSingleNode("Content").InnerText;
                    var labItemName = xNode.SelectSingleNode("LabItemName") == null ? "" : xNode.SelectSingleNode("LabItemName").InnerText;
                    var labRepItemNo = xNode.SelectSingleNode("LabRepItemNo") == null ? "" : xNode.SelectSingleNode("LabRepItemNo").InnerText;
                    var labRepItemName = xNode.SelectSingleNode("LabRepItemName") == null ? "" : xNode.SelectSingleNode("LabRepItemName").InnerText;
                    var labRepResult = xNode.SelectSingleNode("LabRepResult") == null ? "" : xNode.SelectSingleNode("LabRepResult").InnerText;
                    var labRepUnits = xNode.SelectSingleNode("LabRepUnits") == null ? "" : xNode.SelectSingleNode("LabRepUnits").InnerText;
                    var labInd = xNode.SelectSingleNode("LabInd") == null ? "" : xNode.SelectSingleNode("LabInd").InnerText;
                    var labContext = xNode.SelectSingleNode("LabContext") == null ? "" : xNode.SelectSingleNode("LabContext").InnerText;

                    examItemInfoObj.ItemNo = itemNo;
                    examItemInfoObj.ItemDate = itemDate;
                    examItemInfoObj.ExamItemName = examItemName;
                    examItemInfoObj.Prompt = prompt;
                    examItemInfoObj.Content = content;
                    examItemInfoObj.LabItemName = labItemName;
                    examItemInfoObj.LabRepItemNo = labRepItemNo;
                    examItemInfoObj.LabRepItemName = labRepItemName;
                    examItemInfoObj.LabRepResult = labRepResult;
                    examItemInfoObj.LabRepUnits = labRepUnits;
                    examItemInfoObj.LabContext = labContext;

                    responseObj.ExamItemList.Add(examItemInfoObj);
                }
            }

            return responseObj;
        }

        /// <summary>
        /// 获取停诊信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetHaltInfo")]
        public Response4GetHaltInfo GetHaltInfo(Request4GetHaltInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("req");

            XmlNode deptIdNode = xmlDoc.CreateElement("deptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("doctorId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode startDateNode = xmlDoc.CreateElement("startDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("endDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.bkcloud_gethaltinfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetHaltInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetHaltInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var responseObj = new Response4GetHaltInfo();

            var node = xmlDoc.SelectSingleNode("/res/resultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/res/resultDesc");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode == "0")
            {
                responseObj.ResultCode = resultCode;
                responseObj.ResultDesc = resultDesc;

                responseObj.HaltList = new List<Response4GetHaltInfoSubHaltInfo>();
                var nodes = xmlDoc.SelectNodes("/res/haltList/haltInfo");
                foreach (XmlNode xNode in nodes)
                {
                    var haltObj = new Response4GetHaltInfoSubHaltInfo();

                    var scheduleId = xNode.SelectSingleNode("scheduleId") == null ? "" : xNode.SelectSingleNode("scheduleId").InnerText.Trim();
                    var sourceType = xNode.SelectSingleNode("sourceType") == null ? "" : xNode.SelectSingleNode("sourceType").InnerText.Trim();
                    var deptId = xNode.SelectSingleNode("deptId") == null ? "" : xNode.SelectSingleNode("deptId").InnerText.Trim();
                    var deptName = xNode.SelectSingleNode("deptName") == null ? "" : xNode.SelectSingleNode("deptName").InnerText.Trim();
                    var doctorId = xNode.SelectSingleNode("doctorId") == null ? "" : xNode.SelectSingleNode("doctorId").InnerText.Trim();
                    var doctorName = xNode.SelectSingleNode("doctorName") == null ? "" : xNode.SelectSingleNode("doctorName").InnerText.Trim();
                    var title = xNode.SelectSingleNode("title") == null ? "" : xNode.SelectSingleNode("title").InnerText.Trim();
                    var regDate = xNode.SelectSingleNode("regDate") == null ? "" : xNode.SelectSingleNode("regDate").InnerText.Trim();
                    var timeSlice = xNode.SelectSingleNode("timeSlice") == null ? "" : xNode.SelectSingleNode("timeSlice").InnerText.Trim();
                    var startTime = xNode.SelectSingleNode("startTime") == null ? "" : xNode.SelectSingleNode("startTime").InnerText.Trim();
                    var endTime = xNode.SelectSingleNode("endTime") == null ? "" : xNode.SelectSingleNode("endTime").InnerText.Trim();

                    haltObj.ScheduleId = scheduleId;
                    haltObj.SourceType = sourceType;
                    haltObj.DeptId = deptId;
                    haltObj.DeptName = deptName;
                    haltObj.DoctorId = doctorId;
                    haltObj.DoctorName = doctorName;
                    haltObj.Title = title;
                    haltObj.RegDate = regDate;
                    haltObj.TimeSlice = timeSlice;
                    haltObj.StartTime = startTime;
                    haltObj.EndTime = endTime;

                    responseObj.HaltList.Add(haltObj);
                }
            }
            return responseObj;
        }
    }

}